package com.example.xueshen.common.util;

public class  MyPageUtil {
    private MyPageUtil() {
    }

    //当前页pageNum，总页数 pageNum，导航页数 navigatePages
    public static int[] getNavigatePageNums(int current, int pages, int
            navigatePages) {
        int[] navigatePageNums = null;
//总页数少于总显示页面数
        if (pages <= navigatePages) {
            navigatePageNums = new int[pages];
            for (int i = 1; i <= pages; i++) {
                navigatePageNums[i - 1] = i;
            }
        } else {
            int dPage = navigatePages / 2;
            int temp = navigatePages % 2 == 0 ? dPage : dPage + 1;
            navigatePageNums = new int[navigatePages];
//当前页在显示页数的折半页码内
            if (current <= temp && current + navigatePages - 1 <= pages) {
                for (int i = 0; i < navigatePages; i++) {
                    navigatePageNums[i] = i + 1;
                }
//当前页在显示总页码的后半部分
            } else if (current + temp - 1 > pages) {
                for (int i = 0; i < navigatePages; i++) {
                    navigatePageNums[i] = pages - navigatePages + 1 + i;
                }
//中间页码位置
            } else {
                for (int i = 0; i < navigatePages; i++) {
                    navigatePageNums[i] = current - navigatePages / 2 + i;
                }
            }
        }
        return navigatePageNums;
    }
}